class Solution {
public:
    bool kLengthApart(vector<int>& nums, int k) {
        int pos1;
        int i = 0, n = nums.size();
        while (i < n && nums[i] == 0) i++;
        pos1 = i++;
        while (i < n) {
            if (nums[i] == 1) {
                // cout << pos1 << ' ' << i << endl;
                if (i - pos1 - 1 < k) return false;
                pos1 = i;
            }
            i++;
        }
        return true;
    }
};